<template>
  <div class="registerbody">
    <div>
      <label>用户名</label>
      <el-tooltip placement="top">
        <div slot="content">用户名中英文均可，最长14个英文或7个汉字</div>
        <el-button>
          <input v-model="userData.username" class="form-input" type="text" placeholder="请输入用户名">
        </el-button>
      </el-tooltip>
    </div>
    <div>
      <label>邮箱号</label>
      <input v-model="userData.mail" type=" text" placeholder="请输入邮箱号" class="form-input">
    </div>
    <div>
      <label>密码</label>
      <el-tooltip placement="top-end" offset="-180">
        <div slot="content"><p>长度为8~14个字符</p>
          <p>字母/数字以及标点符号至少包含2种</p>
          <p>不允许有空格、中文</p></div>
        <el-button>
          <input v-model="userData.password1" type="password" placeholder="请输入登录密码"
                 class="form-input">
        </el-button>
      </el-tooltip>
      <img alt="" v-show="!passwordHint" class="password-hint"
           src="./image/exclamatory mark black.svg">
      <img alt="" v-show="passwordHint" class="password-hint"
           src="./image/exclamation mark orange.svg">
    </div>
    <div>
      <label>密码</label>
      <input v-model="userData.password2" type="password" placeholder="请再次输入密码" class="form-input">
    </div>
    <div>
      <label>验证码</label>
      <input v-model="userData.code" class="code form-input" type="text" placeholder="请输入验证码">
      <img alt="" @click="toggleimg" ref="code" class="code-img" src="./image/code.png">
    </div>
  </div>
</template>

<script>
import _throttle from 'lodash/throttle'
import {mapState} from 'vuex'

export default {
  name: "Register",
  data() {
    return ({
      passwordHint: false,//当前感叹号的位置，假则表示黑色的感叹号
    })
  },
  methods: {
    //获取图片验证码
    toggleimg: _throttle(function () {
      this.$store.dispatch('Account/getVerificationCode', 'getVerificationCode').then(value => {
        this.$refs.code.src = 'data:image/jpeg;base64,' + value['img']
      })
    }, 5000)
  },
  computed: {
    ...mapState('Account', ['userData'])
  }
}
</script>

<style scoped lang="less">
//注册的主体
.registerbody {
  width: 100%;
  height: 57%;

  div {
    position: relative;
    width: 100%;
    height: 40px;
    margin-bottom: 20px;
    padding-bottom: 5px;

    label {
      box-sizing: border-box;
      height: 100%;
      width: 82px;
      color: #333333;
      font-weight: 200;
      display: block;
      float: left;
      padding-top: 6px;
    }

    .form-input {
      box-sizing: border-box;
      height: 100%;
      width: 340px;
      padding: 10px;
      margin: 1px;
      display: block;
      border-radius: 5px;
      border: 1px #ffffff solid;
      transition: all 0.3ms;

      &:focus {
        border: 2px orange solid;
      }
    }

    .errors {
      position: absolute;
      left: 82px;
      font-size: 13px;
      color: red;
      margin-top: 3px;
    }

    //密码提示感叹号
    .password-hint {
      height: 17px;
      position: absolute;
      left: 396px;
      top: 13px;
      color: #fc0000;
    }

    //验证码
    .code {
    @extend . form-input;
      width: 200px;
    }

    //验证码图片
    .code-img {
      position: relative;
      left: 300px;
      top: -41px;
      height: 40px;
      width: 120px;
    }

    button {
      padding: 0;
      border: 0;
    }
  }
}
</style>